{template header}

<div class="container">


<ol class="breadcrumb">
  <li><a href="{SITE_URL}">首页</a></li>
  <li><a href="{tsUrl('gift')}">微铺</a></li>
  <li><a href="{tsUrl('gift','show',array('id'=>$strGift[giftid]))}">{$strGift['title']}</a></li>
  <li class="active">修改商品</li>
</ol>



<div class="panel panel-default">
  <div class="panel-body">
  <div class="row">
  <div class="col-md-2"></div>
  <div class="col-md-8">
  
  <form method="POST" id="form1" action="{SITE_URL}index.php?app=gift&ac=edit&ts=basedo"  enctype="multipart/form-data">

  <div class="form-group">
    <label>名称：</label>
    <input name="title" id="title" type="text" class="form-control" value="{$strGift['title']}">
  </div>

    <div class="form-group">
      <label>属性：</label>
      <p>

        <input type="radio" name="cate" {if $strGift['cate']==0}checked{/if} value="0" onclick="showjifen()">志愿者福利
        <input type="radio" name="cate" {if $strGift['cate']==1}checked{/if} value="1" onclick="showdanjia()">义卖物品
      </p>
    </div>

 {if $arrType} 
  <div class="form-group">
    <label>类型：</label>

<select class="form-control" name="typeid">
{loop $arrType $key $item}
<option value="{$item[typeid]}" {if $item[typeid]==$strGift[typeid]}selected="select"{/if}>{$item[typename]}</option>
{/loop}
</select>
  </div>
  
  {/if}
  

    <div class="form-group">
      <label>到期时间：</label>
      <p><input class="form-control" name="limittime"  readonly value=" {php echo date('Y-m-d H:i',$strGift[limittime])}" id="limitTime" /></p>
    </div>

    <div class="form-group">
      <label>数目：</label>
      <p><input class="form-control" id="quota" name="quota" value="{$strGift['quota']}" /> </p>
    </div>


    <div class="form-group">
      <label id="label1" {if $strGift[cate]==1}style="display:none"{/if}>所需积分：</label><label id="label2"  {if $strGift[cate]==0}style="display:none"{/if}>单价：</label>
      <p><input class="form-control" id="price" name="price" value="{$strGift['price']}" /> </p>
    </div>

    <div class="form-group">
      <label>发货地：</label>
      <div id="city_3">
        <p><select id="province" name="province" class="prov form-control">{$strGift['province']}</select></p>
        <p><select id="city" name="city" class="city form-control" disabled="disabled">{$strGift['city']}</select></p>
        <p><input type="text" id="address" name="address" class="form-control" value="{$strGift['address']}"></p>
      </div>
    </div>


    <div class="form-group">
      <label>交货方式：</label>
      <p>
        <select name="transfer" id="transfer"  class="form-control">
          <option value="2" {if $strGift[transfer]=="2"}selected{/if}>包邮</option>
          <option value="1" {if $strGift[transfer]=="1"}selected{/if}>自取</option>

        </select>
      </p>
    </div>

    <div class="form-group">
      <label>封面：</label>
      <div class="">
         <img 
            id="picshow" 
            valign="middle" 
            src="{if $strGift[photo]}{php echo tsXimg($strGift[photo],'gift',500,'',$strGift[path])}{else}{SITE_URL}app/gift/skins/default/gift.jpg{/if}" 
            style="height: 150px;">
         <div style="display: flex;">
           <input type="file" id="picfile" name="picfile">
           <div id="picsubmit" class="btn btn-success">上传照片</button> 
           <input type="hidden" name="photo" id="photo" value="{$strGift['photo']}" />
         </div>
      </div>
    </div>

    <div class="form-group">
    <label>简介：</label>
    <div id="tseditor">{$strGift[content]}</div>
    <div style="display: none;">
      <textarea  id="content" name="content">{$strGift[content]}</textarea>
    </div>
    <!--<textarea name="content" id="tseditor"></textarea>-->

  </div>
  <!--
  <div class="form-group">
    <label>福利海报：</label>
	
{if $strGift['photo']}
<p><img src="{php echo tsXimg($strGift['photo'],'gift','300','200',$strGift['path'])}" /></p>
{/if}
	
    <input type="file" name="photo" />
  </div>
  -->
  
<input type="hidden" name="giftid" value="{$strGift[giftid]}" />
  <input class="btn btn-success" type="submit" value="修改">  <a href="{tsUrl('gift','show',array('id'=>$strGift[giftid]))}">返回</a>
  
</form>

</div>
</div>


</div>
</div>
</div>

{php doAction('tseditor')}

<script src="{SITE_URL}public/js/image.js"></script>
<script>

  $(function(e){
    $('#form1').on('submit', function(e) {
      var title  = $('#title').val();
      var limittime  = $('#limitTime').val();
      var price = $('#price').val();
      var quota  = $('#quota').val();
      var content  = $('#content').val();
      var photo = $('#photo').val();

      if(title==''){
        bootbox.alert('名称必填');
        return false;
      }

      if(limittime==''){
        bootbox.alert('到期时间必填');
        return false;
      }

      if(quota==''){
        bootbox.alert('数量必填');
        return false;
      }

      if(price==''){
        bootbox.alert('价格必填');
        return false;
      }
      if(photo==''){
          bootbox.alert('必须上传封面');
          return false;
      }

      if (content == '<p><br></p>') {
        bootbox.alert('内容不能为空');
        return false;
      }

    });


    var picFile = null;
    // 封面上传监听
    $('#picfile').on("change", function (e) {
      $("#photo").val('')
      $("#picshow").attr('src', ''); 

      let file = e.target.files[0]
      compressImg(file, 0.25).then(res => {
        $("#picshow").attr('src', window.URL.createObjectURL(res.file)); 
        picFile = res.file
      })
    });
    
    var upload_url = "{SITE_URL}index.php?app=gift&ac=do&ts=photo";
    $('#picsubmit').on("click", function () {
      if (!picFile) {
        return bootbox.alert('请选择图片！');
      }
      var formData = new FormData();
      formData.append("file", picFile, picFile.filename);
      formData.append("upload_file", true);
      console.log(formData, picFile)
      $.ajax({
        url: upload_url,
        data: formData,
        processData: false,
        contentType: false,
        type: 'POST',
        success: function(data){
          if (data != 0) {
            $("#photo").val(data)
            picFile = null
              return bootbox.alert('图片上传成功！');
          } else {
              return bootbox.alert('图片上传失败！');
          }
        }
      });
    });

  });

  function showjifen(){
    $('#label2').css('display','none');
    $('#label1').css('display','block');
  }

  function showdanjia(){
    $('#label1').css('display','none');
    $('#label2').css('display','block');
  }

  function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);//获取当前月份的日期，不足10补0
    var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();//获取当前几号，不足10补0
    return y+"-"+m+"-"+d;
  }

  $('#limitTime').datetimepicker({
    language:  'zh-CN',
    autoclose: true,
    endDate: GetDateStr(5),
    format: 'yyyy-mm-dd hh:ii'
  });

</script>
{template footer}